<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    <div id="but">zaaaa</div>
    <script>
        var eve = new Event('test');
        var btn = document.getElementById('but');
        btn.addEventListener('test', function() {
            console.log('test dispatch');
        });
        setTimeout(function() {
            btn.dispatchEvent(eve);
        }, 1000)
    </script>
    <script>
        var cuseve = new CustomEvent('custom', {
            detail: {
                detail2: 'zcc',
                detail3: 'melody',
            },
            bubbles: 'true',
            cancelable: 'true',
        });
        var btn2 = document.getElementById('but');
        btn2.addEventListener('custom', function(e) {
            console.log(e, e.detail, e.bubbles, e.cancelable);
        });
        setTimeout(function() {
            btn2.dispatchEvent(cuseve);
        }, 2000)
    </script>
</body>
</html>